package cn.gok.controller;

import cn.gok.entity.Clazz;
import cn.gok.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazz")
//本次测试统一使用ResultFul风格进行测试，请老师注意
public class ClazzController {
    @Autowired
    ClazzService clazzService;

    //查询所有班级的信息
    @GetMapping
    public List<Clazz> getAll() {
        return clazzService.list(null);
    }

    //根据ID查询班级信息 http://localhost:8080/clazz/1
    @GetMapping("{cid}")
    public Clazz getClazzById(@PathVariable Long cid) {
        return clazzService.getById(cid);
    }

    //查询所有班级信息和对应的学生信息,具体方法实现统一在service层
    @GetMapping("/selectStudentCidByClazz")
    public List<Clazz> selectStudentCidByClazz() {
        return clazzService.selectStudentCidByClazz();
    }

    //添加班级
    @PostMapping
    public boolean saveClazz(@RequestBody Clazz clazz) {
        return clazzService.save(clazz);
    }

    //修改班级信息
    @PutMapping
    public boolean updateClazz(@RequestBody Clazz clazz) {
        return clazzService.updateById(clazz);
    }

    //根据id删除班级
    @DeleteMapping("{cid}")
    public boolean deleteByClazz(@PathVariable Long cid) {
        return clazzService.removeById(cid);
    }

    //批量删除班级
    @DeleteMapping
    public boolean deleteClazzByIds(@RequestBody List<Integer> ids) {
        return clazzService.removeByIds(ids);
    }
}
